﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ParticipacionVecinalWeb.Models.Maestro;
using BusinessEntities;
using BusinessLayer.ParticipacionVecinal;

namespace ParticipacionVecinalWeb.Controllers.Maestro {
    public class MaestroController : Controller {
        //
        // GET: /Maestro/

        public JsonResult ListaSector() {

            var lst = new List<M>();

            SectorBL obj = new SectorBL();

            lst = (from x in obj.List()
                   select new M {
                       V = x.Id.ToString(),
                       N = x.Nombre
                   }).ToList();

            var vjson = Json(lst, JsonRequestBehavior.AllowGet);
            vjson.MaxJsonLength = int.MaxValue;

            return vjson;
        }

        public JsonResult ListaSubSector(String subSector) {

            var lst = new List<M>();

            int iSubSctor = 0;

            if (!int.TryParse(subSector, out iSubSctor)) {
                var vjsona = Json("", JsonRequestBehavior.AllowGet);
                vjsona.MaxJsonLength = int.MaxValue;
                return vjsona;
            }

            SubsectorBL obj = new SubsectorBL();

            lst = (from x in obj.List(iSubSctor)
                   //where x.IdSector == iSubSctor
                   select new M {
                       V = x.Id.ToString(),
                       N = x.Nombre
                   }).ToList();

            //var strList = (from x in lst where x.K == subSector select new { N = x.N, V = x.V }).ToList();

            var vjson = Json(lst, JsonRequestBehavior.AllowGet);
            vjson.MaxJsonLength = int.MaxValue;

            return vjson;
        }

        public JsonResult ListaEstado() {
            var lst = new List<M>();
            EstadoBL obj = new EstadoBL();
            lst = (from x in obj.List()
                   select new M {
                       V = x.Id.ToString(),
                       N = x.Nombre
                   }).ToList();
            var vjson = Json(lst, JsonRequestBehavior.AllowGet);
            vjson.MaxJsonLength = int.MaxValue;
            return vjson;
        }


        public JsonResult ListaArea() {

            var lst = new List<M>();
            AreaBL obj = new AreaBL();
            lst = (from x in obj.List()
                   select new M {
                       V = x.IdArea.ToString(),
                       N = x.Nombre
                   }).ToList();

            var vjson = Json(lst, JsonRequestBehavior.AllowGet);
            vjson.MaxJsonLength = int.MaxValue;

            return vjson;
        }


    }
}
